//
//  JJMainNavigationController.swift
//  JJSina
//
//  Created by mac on 2017/11/30.
//  Copyright © 2017年 xinyuan. All rights reserved.
//

import UIKit

class JJMainNavigationController: UINavigationController, UIGestureRecognizerDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()
        // 解决手势失效问题
        interactivePopGestureRecognizer?.delegate = self
        
    }
    // 将要接受手势点击
    func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
        return childViewControllers.count != 1
    }
    
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
       
        // 控制器进入了二级界面
        if childViewControllers.count > 0 {
            // 设置title
            var title = "返回"
            if childViewControllers.count == 1 {
                title = childViewControllers.first?.title ?? ""
                // 隐藏标签栏
            viewController.hidesBottomBarWhenPushed = true
                
            }
            
        viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(imageName: "navigationbar_back_withtext", title: title, target: self, action: #selector(leftClick))
            
        }
        super.pushViewController(viewController, animated: animated)
        
    }

    @objc private func leftClick() {
        popViewController(animated: true)
    }

}
